//
//  SpectailDetailHeaderCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/20.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol SpectailDetailHeaderCellDelegate {
    func companyCallBtnClicked(text: String)
    func agentCallBtnClicked(text: String)
    func collectionAction()
}

class SpectailDetailHeaderCell: UITableViewCell, UIWebViewDelegate {
    var delegate: SpectailDetailHeaderCellDelegate?
    var modelList: specialDetailInfo?{
        didSet{
            self.showInfo()
           
        }
    }
    
    
    //var intotalCellHeight: CGFloat = 0
    @IBOutlet weak var iv: UIImageView!
    @IBOutlet weak var facturer_size: UILabel!//厂商_规格
    @IBOutlet weak var facturer_nature:UILabel!//性质
    @IBOutlet weak var facturer_industry: UILabel!//行业
    @IBOutlet weak var facturer_address: UILabel!//地址
    @IBOutlet weak var facturer_tel: UILabel!
    @IBOutlet weak var agent_size: UILabel!//代理_...
    @IBOutlet weak var agent_nature: UILabel!
    @IBOutlet weak var agent_industry: UILabel!
    @IBOutlet weak var agent_address: UILabel!
    @IBOutlet weak var agent_tel: UILabel!
    
    @IBOutlet var factuterView: UIView!
    @IBOutlet var agentView: UIView!
    @IBOutlet var webView: UIView!
    
    @IBOutlet weak var tureWebView: UIView!
    
    @IBOutlet var facturerViewHeight: NSLayoutConstraint!
    @IBOutlet var agentViewHeight: NSLayoutConstraint!
    @IBOutlet var webViewHeight: NSLayoutConstraint!
    
    @IBOutlet weak var collectionBtn: UIButton!
    var count: Int = 0
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
       
    }
    
    func setCellContentWithCellInfo(cellInfo: specialDetailInfo?) -> Void {
        self.modelList = cellInfo
        if self.modelList?.showtype == "cs"{
            self.facturerViewHeight.constant = 148
            self.agentViewHeight.constant = 0
            
        }else if self.modelList?.showtype == "dl"{
            self.facturerViewHeight.constant = 0
            self.agentViewHeight.constant = 148
            
        }else{
            self.facturerViewHeight.constant = 148
            self.agentViewHeight.constant = 148
            
        }
        self.factuterView.layoutIfNeeded()
        self.agentView.layoutIfNeeded()

    }
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
  
    func showInfo(){
        self.iv.sd_setImageWithURL(NSURL(string: (self.modelList!.logo)), placeholderImage: UIImage(named: "placeholder"))
        self.facturer_size.text = self.modelList?.csscale
        self.facturer_nature.text = self.modelList?.csnature
        self.facturer_industry.text = self.modelList?.cstype
        self.facturer_address.text = self.modelList?.csaddress
        self.facturer_tel.text = self.modelList?.csphone
        self.agent_size.text = self.modelList?.dlscale
        self.agent_nature.text = self.modelList?.dlnature
        self.agent_industry.text = self.modelList?.dltype
        self.agent_address.text = self.modelList?.dladdress
        self.agent_tel.text = self.modelList?.dlphone
        if self.modelList?.isshoucang == true{
            self.collectionBtn.setImage(UIImage(named: "collection_selected"), forState: UIControlState.Normal)
        }else{
            self.collectionBtn.setImage(UIImage(named: "collection"), forState: UIControlState.Normal)
        }
    }
    
    @IBAction func companyCallBtnClicked(sender: UIButton){
        delegate?.companyCallBtnClicked((self.modelList?.csphone)!)
    }
    @IBAction func agentCallBtnClicked(sender: UIButton){
        delegate?.agentCallBtnClicked((self.modelList?.dlphone)!)
        
    }
    
    @IBAction func collectionClicked(sender: UIButton){
        delegate?.collectionAction()
    }
    
}
